<html>
	<body>
		<script>
			// "use strict"

			// name = "aven";
			// var age = 18;

			// var obj = {
			//       name: "ake",
			//       age: '20',
			//       test: function(){
			//           console.log( "name:" + this.name + ", " + "age:" + this.age );
			//   }
			// };

			/*
			obj.test(); 
			obj.test.call()
			*/

			var name = "testName";
			var age = 18;

			var obj = {
				name: "ake",
				age: this.age,
				test: function(gender, home) {
					console.log("name: ", this.name, "age:", this.age, "gender:", gender, "home: ", home);
				}
			};

			var person = {
				name: "aven",
				age: 21
			}
			obj.test.call(person, "female", "China")
			obj.test.apply(person, ["female2", "China2"])
			obj.test.bind(person, "female3", "China3")()
			obj.test.bind(person, ["female4", "China4"])()
			obj.test.bind(this, "female5", "China5")()

			/*
			document.addEventListener('click', function(e){
			    console.log(this);
			    setTimeout(function(){
			        console.log(this);
			    }, 200);
			}, false);
			*/


			// let pepole = {
			//     name:'jike',
			//     init:function(){
			//         //为body添加一个点击事件，看看这个点击后的this属性有什么不同
			//         document.body.onclick = ()=>{
			//             alert(this.name);//?? this在浏览器默认是调用时的对象,可变的？                  
			//         }
			//     }
			// }
			// pepole.init();


			// let pepole = {
			//     name2:'jike',
			//     init:()=>{
			//         //为body添加一个点击事件，看看这个点击后的this属性有什么不同
			//         document.body.onclick = ()=>{
			//             alert(this.name2);//?? this在浏览器默认是调用时的对象,可变的？                  
			//         }
			//     }
			// }
			// pepole.init();

			/*
			let B = (b)=>{
			  // console.log(arguments);
			}
			B(2,92,32,32);   // Uncaught ReferenceError: arguments is not defined
			
			let C = (...c) => {
			  console.log(c);
			}
			C(3,82,32,11323);  // [3, 82, 32, 11323]
			*/

			let nameThis = "ab"
			const objThis = {
				nameThis: "OB",
				fn: function() {
					console.log(this, "ThisFn")
				},
				fn2: () => {
					console.log(this, "ThisFn2")
				}
			}
			objThis.fn()
			objThis.fn2()

			let obj2 = {
				a: 10,
				b: function(n) {
					let f = (n) => n + this.a;
					return f(n);
				},
				c: function(n) {
					let f = (n) => {
						console.log(this)
						return n + this.a
					};
					let m = {
						a: 20
					};
					return f.call(m, n);
				}
			};
			console.log(obj2.b(1)); // 11
			console.log(obj2.c(1)); // 11

			const Person = {
				'name0': 'little bear',
				'age': 18,
				'sayHello': function() {
					// setInterval(() => console.log('我叫' + this.name0 + '我今年' + this.age + '岁!'), 1000)
				}
			}
			Person.sayHello()

			/*定义一个人类*/
			function PersonFun(name, age) {
				this.name = name;
				this.age = age;
			}
			/*定义一个学生类*/
			function Student(name, age, grade) {
				PersonFun.apply(this, arguments);
				this.grade = grade;
			}
			//创建一个学生类  
			var student = new Student("zhangsan", 21, "一年级");
			//测试  
			console.log("name: " + student.name + "\n" + "age: " + student.age + "\n" + "grade: " + student.grade);

			function Person1() {
				this.name = "person1";
				this.sayName = function() {
					// console.log('\n' + this.name);
				}
			}

			function Person2() {
				this.name = "person2";
				console.log(this, "Person2")
			}
			var P1 = new Person1()
			var P2 = new Person2();
			Person2.call(P1);
			console.log(P1, "P1")
			console.log(P2, "P2")
			P1.sayName(); //person2

			function fn(n1, n2) {
				// console.log(arguments, "arguments")
				// this.ages = 18
				console.log(this.ages, "this.ages")
				return this.ages
			}
			let objFn = {
				names: "aven",
				ages: 21,
				fn: fn
			};
			fn.apply(objFn, [11, {
				a: 123
			}])
		</script>
	</body>
</html>